<template>
  <basic-container>
    <avue-crud
      ref="crud"
      :option="option"
      :table-loading="loading"
      :data="data"
      :defaults.sync="defaults"
      :page.sync="page"
      :search.sync="query"
      :permission="permissionList"
      @row-update="rowUpdate"
      @row-del="rowDel"
      @search-change="searchChange"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
    >
      <template slot="menuRight">
        <user-table-config :option="option" @confirm="(val) => handleSetUserConfig(val, pageCode)"></user-table-config>
      </template>
      <template slot="menuLeft">
        <el-button type="primary" size="small" icon="el-icon-plus" v-if="permission.vehicleAccount_add" @click="addBtn">新 增</el-button>
        <el-button type="danger" size="small" icon="el-icon-delete" v-if="permission.vehicleAccount_delete" @click="handleDelete">删 除 </el-button>
        <!--        <el-button type="success" size="small" icon="el-icon-upload2" @click="handleImport">导入</el-button>-->
        <el-button type="warning" size="small" icon="el-icon-download" @click="$refs.exportComp.visible = true">导 出</el-button>
        <el-button type="warning" size="small" icon="el-icon-delete" v-if="permission.vehicleAccount_unbinding" @click="batchUnbinding">解 绑</el-button>
        <el-dropdown @command="handleSelectItem">
          <el-button type="success" size="small" icon="el-icon-upload2">导 入</el-button>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command="vehicleAccount">载具台账导入</el-dropdown-item>
            <el-dropdown-item command="vehicleVolume">载具容量导入</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </template>
      <template slot-scope="{ row, index }" slot="menu">
        <el-button icon="el-icon-view" size="small" type="text" v-if="permission.vehicleAccount_view" @click="rowView(row)">详情</el-button>
        <el-button icon="el-icon-edit" size="small" type="text" v-if="permission.vehicleAccount_edit" :disabled="row.status != 1" @click="rowUpdate(row)">编辑</el-button>
        <el-button icon="el-icon-delete" size="small" type="text" v-if="permission.vehicleAccount_delete" :disabled="row.status != 1" @click="$refs.crud.rowDel(row, index)"
          >删除</el-button
        >
        <el-button icon="el-icon-view" size="small" type="text" v-if="permission.vehicleAccount_viewInUseInfo" @click="queryInUseInfo(row)">在用信息</el-button>
      </template>
    </avue-crud>

    <el-dialog
      class="vehicleAccountDialog"
      v-dragDirectives
      ref="dialog"
      :title="dialogTitle"
      append-to-body
      :visible.sync="showDialog"
      :close-on-click-modal="false"
      top="5vh"
      width="70%"
      @close="closeDialog"
      @open="vehicleOpen"
    >
      <avue-form ref="basicInfoForm" v-if="showDialog" v-model="form" :option="dialogOption"></avue-form>
      <h3 v-if="dialogTitle === '查看'" class="subTitle"><i class="el-icon-vertical-bar mr10"></i>绑定包装信息</h3>
      <avue-crud v-if="dialogTitle === '查看'" :option="packInfoOption" :table-loading="loading" :data="packInfoList" ref="packInfoCrud"></avue-crud>

      <template v-if="dialogTitle !== '新增'">
        <h3 class="subTitle"><i class="el-icon-vertical-bar mr10"></i>载具容量</h3>
        <el-button
          v-if="dialogTitle === '新增' || (dialogTitle === '编辑' && form.status === 1)"
          type="primary"
          size="small"
          icon="el-icon-plus"
          @click="addVehicleCapacityBtn"
          style="margin-bottom: 10px"
          >新 增</el-button
        >

        <avue-crud
          :option="vehicleCapacityOption"
          :data="vehicleCapacityList"
          ref="packInfoCrud"
          :table-loading="vehicleCapacity.loading"
          v-model="vehicleCapacity.form"
          :page.sync="vehicleCapacity.page"
          :search.sync="vehicleCapacity.search"
          @search-change="searchVehicleChange"
          @search-reset="searchVehicleReset"
          @row-save="vehicleCapacityRowSave"
          @row-update="vehicleCapacityRowUpdate"
          @row-del="vehicleCapacityRowDel"
        ></avue-crud>
      </template>

      <span slot="footer" class="dialog-footer">
        <el-button v-if="dialogTitle === '新增'" type="primary" size="small" @click="submit"> <i class="el-icon-circle-plus-outline"></i><span>保 存</span> </el-button>
        <el-button v-if="dialogTitle === '编辑'" type="primary" size="small" @click="submit"> <i class="el-icon-circle-check"></i><span>修 改</span> </el-button>
        <el-button size="small" @click="showDialog = false"><i class="el-icon-circle-close"></i><span>取 消</span></el-button>
      </span>
    </el-dialog>

    <el-dialog ref="dialog" title="载具在用信息" append-to-body :visible.sync="inUseInfoShowDialog" :close-on-click-modal="false" top="5vh" width="70%" @close="closeDialog">
      <avue-crud :option="vehicleInUseInfoOption" :data="vehicleInUseInfoList" ref="vehicleInUseInfoCrud" @selection-change="vehicleInUseInfoSelectionChange">
        <template slot-scope="{ row }" slot="menu">
          <el-button icon="el-icon-delete" size="small" type="text" @click="unbinding(row)">解绑</el-button>
        </template>
      </avue-crud>
      <span slot="footer" class="dialog-footer">
        <el-button v-if="isBatchUnbinding" type="primary" size="small" @click="unbinding()"> <i class="el-icon-delete"></i><span>解绑</span> </el-button>
        <el-button size="small" @click="inUseInfoShowDialog = false"><i class="el-icon-circle-close"></i><span>取 消</span></el-button>
      </span>
    </el-dialog>

    <common-modal-template ref="commonModalTemplate" :key="timer" :option="tableOption" @getSelectedRows="getSelectedRows" @newKey="newKey"></common-modal-template>
    <importDialogComp
      :title="importConfig.title"
      :export-name="importConfig.exportName"
      :url="importConfig.exportUrl"
      :visible.sync="importConfig.show"
      :another-export-method="true"
      :export-code="importConfig.exportCode"
      @submit="codeClose"
    ></importDialogComp>
    <export-comp ref="exportComp" page-api-url="mes-product/carrier/listCarrier" :option="option" :page="page" :query="query" file-name="载具台账" page-api-method="POST">
    </export-comp>
  </basic-container>
</template>
<script>
import { getList, getDetail, add, update, remove, getInuseInfo, unbindingCarrier, carrierPageList, carrierSave, carrierRemove } from '@/api/vehicle-manage/vehicle-account';
import { mapGetters } from 'vuex';
import importDialogComp from '@/components/dialog/import/index.vue';
import CommonModalTemplate from '@/components/common-modal-template/common-modal-template';
import exportComp from '@/components/export-comp';
import userTableConfig from '@/components/user-table-config';
import userConfig from '@/mixins/userConfig';
export default {
  name: 'VehicleManageVehicleAccount',
  components: {
    CommonModalTemplate,
    importDialogComp,
    userTableConfig,
    exportComp
  },
  mixins: [userConfig()],
  data() {
    return {
      pageCode: 'VEHIDE_ACCOUNT',
      rowData: {},
      form: {},
      defaults: {},
      query: {},
      loading: true,
      page: {
        pageSize: 20,
        currentPage: 1,
        total: 0
      },
      exportData: [],
      importConfig: {
        show: false,
        exportUrl: '/api/mes-admin/excelimportconfig/import/code/mfg_carrier',
        exportCode: 'mfg_carrier',
        exportName: '',
        title: ''
      },
      selectionList: [],
      option: {
        height: 'calc(100vh - 440px)',
        calcHeight: 30,
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        border: true,
        index: true,
        indexLabel: '序号',
        addBtn: false,
        viewBtn: false,
        editBtn: false,
        delBtn: false,
        selection: true,
        menuWidth: 250, //弹框内字段宽度属性
        dialogWidth: 880, //弹框宽度属性
        labelWidth: '110',
        dialogClickModal: false,
        columnBtn: false,
        column: [
          {
            label: '名称',
            prop: 'name',
            search: true,
            searchSpan: 4
          },
          {
            label: '编码',
            prop: 'sequenceNumber',
            search: true,
            searchSpan: 4,
            disabled: false
          },
          {
            label: '类型',
            prop: 'carrierType',
            type: 'select',
            search: true,
            searchSpan: 4,
            dicUrl: '/api/blade-system/dict/dictionary?code=carrier_type',
            props: {
              label: 'dictValue',
              value: 'dictKey'
            }
          },
          {
            label: '可装多种物料',
            prop: 'isMixable',
            type: 'switch',
            dicData: [
              {
                label: '否',
                value: false
              },
              {
                label: '是',
                value: true
              }
            ],
            value: false
          },
          {
            label: '载具状态',
            prop: 'status',
            search: true,
            searchSpan: 4,
            type: 'select',
            dicUrl: '/api/blade-system/dict/dictionary?code=carrier_status',
            props: {
              label: 'dictValue',
              value: 'dictKey'
            }
          },
          {
            label: '数据来源',
            prop: 'dataSource',
            dicData: [
              {
                label: '系统新增',
                value: 0
              },
              {
                label: '生产临时创建',
                value: 1
              }
            ]
          }
        ]
      },
      dialogTitle: '新增',
      showDialog: false,
      dialogOption: {
        submitBtn: false,
        emptyBtn: false,
        labelWidth: '150',
        column: [
          {
            label: '名称',
            prop: 'name',
            rules: [
              {
                required: true,
                message: '请输入名称',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '编码',
            prop: 'sequenceNumber',
            rules: [
              {
                required: true,
                message: '请输入编码',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '类型',
            prop: 'carrierType',
            type: 'select',
            dicUrl: '/api/blade-system/dict/dictionary?code=carrier_type',
            props: {
              label: 'dictValue',
              value: 'dictKey'
            },
            placeholder: '请选择 类型',
            rules: [
              {
                required: true,
                message: '请选择类型',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '可装不同种物料',
            prop: 'isMixable',
            type: 'switch',
            dicData: [
              {
                label: '否',
                value: false
              },
              {
                label: '是',
                value: true
              }
            ],
            value: false
          }
        ]
      },
      data: [],
      packInfoOption: {
        height: 300,
        calcHeight: 30,
        tip: false,
        border: true,
        index: true,
        indexLabel: '序号',
        addBtn: false,
        viewBtn: false,
        editBtn: false,
        delBtn: false,
        selection: false,
        dialogClickModal: false,
        refreshBtn: false,
        columnBtn: false,
        menu: false,
        column: [
          {
            label: '产品编码',
            prop: 'partNo'
          },
          {
            label: '产品名称',
            prop: 'name'
          },
          {
            label: '产品数量',
            prop: 'quantity'
          },
          {
            label: '条码类型',
            prop: 'goodsType',
            dicData: [
              {
                label: '包装条码',
                value: 'PACK'
              },
              {
                label: '产品序列号',
                value: 'PRODUCT'
              },
              {
                label: '无',
                value: 'NONE'
              }
            ]
          },
          {
            label: '序列号',
            prop: 'goodsNo'
          },
          {
            label: '操作人',
            prop: 'createUser'
          },
          {
            label: '绑定时间',
            prop: 'createTime'
          }
        ]
      },
      packInfoList: [],
      vehicleCapacity: {
        form: {},
        loading: false,
        search: {},
        page: {
          pageSize: 20,
          currentPage: 1,
          total: 0
        }
      },
      vehicleCapacityOption: {
        height: 300,
        calcHeight: 30,
        tip: false,
        border: true,
        index: true,
        indexLabel: '序号',
        searchShow: true,
        searchMenuSpan: 6,
        addBtn: false,
        viewBtn: false,
        selection: false,
        refreshBtn: false,
        columnBtn: false,
        addRowBtn: true,
        menuWidth: 150,
        menu: true,
        column: [
          {
            label: '物料编码',
            prop: 'partNo',
            search: true,
            searchSpan: 6,
            searchType: 'input',
            type: 'search',
            appendClick: () => {
              this.openCommonModal();
            },
            rules: [
              {
                required: true,
                message: '请输入物料编码',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '物料名称',
            prop: 'name',
            disabled: true
          },
          {
            label: '物料型号',
            prop: 'partModel',
            disabled: true
          },
          {
            label: '最大容量',
            prop: 'maxCapacity',
            type: 'number',
            rules: [
              {
                required: true,
                message: '请输入最大容量',
                trigger: 'blur'
              }
            ]
          }
        ]
      },
      vehicleCapacityList: [],
      tableOption: {},
      timer: new Date().getTime(),
      inUseInfoShowDialog: false,
      vehicleInUseInfoOption: {
        height: 500,
        calcHeight: 30,
        tip: false,
        border: true,
        index: true,
        indexLabel: '序号',
        addBtn: false,
        viewBtn: false,
        editBtn: false,
        delBtn: false,
        selection: false,
        refreshBtn: false,
        columnBtn: false,
        addRowBtn: false,
        menuWidth: 150,
        menu: false,
        column: [
          {
            label: '载具编码',
            prop: 'sequenceNumber'
          },
          {
            label: '在用工单',
            prop: 'workOrderNo'
          },
          {
            label: '所处工序',
            prop: 'routeName'
          },
          {
            label: '装载产品',
            prop: 'partNo'
          },
          {
            label: '产品数量',
            prop: 'packingSpecification'
          }
        ]
      },
      vehicleInUseInfoList: [],
      isBatchUnbinding: false,
      inUseSelectionList: []
    };
  },
  mounted() {
    this.$nextTick(() => {
      this.$structuralSplit();
    });
  },
  computed: {
    ...mapGetters(['permission']),
    permissionList() {
      return {
        addBtn: this.vaildData(this.permission.vehicleAccount_add, false),
        viewBtn: this.vaildData(this.permission.vehicleAccount_view, false),
        delBtn: this.vaildData(this.permission.vehicleAccount_delete, false),
        editBtn: this.vaildData(this.permission.vehicleAccount_edit, false)
      };
    },
    ids() {
      let ids = [];
      this.selectionList.forEach((ele) => {
        ids.push(ele.id);
      });
      return ids;
    }
  },
  methods: {
    handleDelete() {
      if (this.selectionList.length === 0) {
        this.$message.warning('请选择至少一条数据');
        return;
      }
      for (let i = 0; i < this.selectionList.length; i++) {
        if (this.selectionList[i].status != 1) {
          this.$message.warning(`编码为${this.selectionList[i].sequenceNumber}的载具当前状态不能删除！`);
          return;
        }
      }
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          return remove(this.ids);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
          this.$refs.crud.toggleSelection();
        });
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = {}) {
      this.loading = true;
      getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then((res) => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this._forEach(this.data, (item) => {
          item.status = String(item.status);
        });
        this.loading = false;
        this.selectionClear();
      });
    },
    addBtn() {
      this.showDialog = true;
      this.dialogTitle = '新增';
      this.$nextTick(() => {
        this.$refs.basicInfoForm.allDisabled = false;
      });
      const column = this.findObject(this.dialogOption.column, 'sequenceNumber');
      column.disabled = false;
    },
    /**
     * 提交
     */
    submit() {
      if (this.dialogTitle !== '新增' && !this.form.isMixable && this.vehicleCapacityList.length > 1) {
        this.$message({
          type: 'warning',
          message: '当前载具不可装载不同种物料！'
        });
        return;
      }
      if (this.dialogTitle === '新增') {
        this.$refs.basicInfoForm.validate((valid, done) => {
          if (valid) {
            this.form.isGood = false;
            this.form.isReusable = false;
            this.form.quantity = 0;
            this.form.packQuantity = 0;
            // this.form.carrierProductList = this.vehicleCapacityList;
            add(this.form).then(
              (res) => {
                this.onLoad(this.page);
                this.$message({
                  type: 'success',
                  message: res.data.msg
                });
                this.showDialog = false;
                done();
              },
              (error) => {
                done();
              }
            );
          }
        });
      } else {
        this.$refs.basicInfoForm.validate((valid, done) => {
          if (valid) {
            // this.form.carrierProductList = this.vehicleCapacityList;
            update(this.form).then(
              (res) => {
                this.onLoad(this.page);
                this.$message({
                  type: 'success',
                  message: res.data.msg
                });
                this.showDialog = false;
                done();
              },
              (error) => {
                done();
              }
            );
          }
        });
      }
    },
    /**
     * 查看详情数据
     */
    rowView(row) {
      this.rowData = structuredClone(row);
      this.showDialog = true;
      this.dialogTitle = '详情';
      this.$nextTick(() => {
        this.$refs.basicInfoForm.allDisabled = true;
      });
      getDetail(row.id).then((res) => {
        this.form = res.data.data;
        this.packInfoList = this._get(this.form, 'carrierGoodsDtoList', []);
        // this.vehicleCapacityList = this._get(this.form, 'carrierProductList', []);
        this.vehicleCapacityOption.menu = false;
      });
    },
    rowUpdate(row) {
      this.showDialog = true;
      this.rowData = structuredClone(row);
      this.dialogTitle = '编辑';
      this.$nextTick(() => {
        this.$refs.basicInfoForm.allDisabled = false;
      });
      const column = this.findObject(this.dialogOption.column, 'sequenceNumber');
      column.disabled = true;
      getDetail(row.id).then((res) => {
        this.form = res.data.data;
        this.packInfoList = this._get(this.form, 'carrierGoodsDtoList', []);
        // this.vehicleCapacityList = this._get(this.form, 'carrierProductList', []);
        if (this.form.status === 1) {
          this.vehicleCapacityOption.menu = true;
        } else {
          this.vehicleCapacityOption.menu = false;
        }
      });
    },
    rowDel(row) {
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          return remove([row.id]);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
        });
    },
    // handleImport() {
    //   this.importConfig.show = true;
    // },
    handleSelectItem(command) {
      console.log(command);
      let code;
      let url;
      let title;
      let exportName;
      if (command === 'vehicleAccount') {
        code = 'mfg_carrier';
        url = '/api/mes-admin/excelimportconfig/import/code/mfg_carrier';
        title = '载具台账导入';
        exportName = '载具台账导入模板.xlsx';
      } else {
        code = 'mfg_carrier_capacity';
        url = '/api/mes-admin/excelimportconfig/import/code/mfg_carrier_capacity';
        title = '载具容量导入';
        exportName = '载具容量导入.xlsx';
      }
      //  const code = command === 'vehicleAccount' ? 'mfg_carrier' : 'mfg_carrier_capacity';
      //  const url =
      //    command === 'vehicleAccount' ? '/api/mes-admin/excelimportconfig/import/code/mfg_carrier' : '/api/mes-admin/excelimportconfig/import/code/mfg_carrier_capacity';
      // const  title
      this.importConfig = {
        exportCode: code,
        title,
        exportUrl: url,
        show: true,
        exportName
      };
      // this.importConfig.exportCode = code;
      // this.importConfig.title = title;
      // this.importConfig.exportUrl = url;
      // this.importConfig.show = true;
      // this.importConfig.exportName = exportName;
    },
    codeClose(value) {
      if (value) {
        this.onLoad(this.page);
      }
    },
    closeDialog() {
      this.$refs.basicInfoForm.resetFields();
      this.form = {};
      this.vehicleCapacityList = [];
    },
    addVehicleCapacityBtn() {
      if (!this.form.isMixable && this.vehicleCapacityList.length == 1) {
        this.$message({
          type: 'warning',
          message: '当前载具不可装载不同种物料！'
        });
        return;
      }
      this.$refs.packInfoCrud.rowAdd();
    },
    openCommonModal() {
      this.$refs.commonModalTemplate.showModal();
      this.tableOption = {
        modalTitle: '选择物料信息（双击进行选择）',
        url: '/api/mes-admin/part-master/page',
        isPage: true,
        index: false,
        rowSelectionType: 'single',
        columnDefs: [
          {
            label: '类型',
            prop: 'categoryId',
            type: 'tree',
            dicUrl: '/api/mes-admin/part-category/tree',
            props: {
              label: 'title',
              value: 'id'
            }
          },
          {
            label: '物料编码',
            prop: 'partNo',
            search: true,
            minWidth: 150
          },
          {
            label: '名称',
            prop: 'name',
            search: true,
            width: 150
          },
          {
            label: '物料型号',
            prop: 'partModel',
            width: 150
          },
          {
            label: '描述',
            prop: 'description',
            width: 150
          },
          {
            label: '版本',
            prop: 'revision',
            width: 150
          }
        ]
      };
    },
    /**
     * 双击模态框行
     */
    getSelectedRows(row) {
      this.$set(this.vehicleCapacity.form, 'partNo', row.partNo);
      this.$set(this.vehicleCapacity.form, 'name', row.name);
      this.$set(this.vehicleCapacity.form, 'partModel', row.partModel);
    },
    /**
     * 重新加载公用表格弹窗组件
     */
    newKey() {
      this.timer = new Date().getTime();
    },
    vehicleCapacityRowSave(form, done) {
      form.carrierId = this.rowData.id;
      carrierSave(form)
        .then(() => {
          this.getCarrierList(this.vehicleCapacity.page);
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
          done();
        })
        .catch(() => {});
    },
    vehicleCapacityRowUpdate(form, index, done) {
      form.carrierId = this.rowData.id;
      carrierSave(form)
        .then(() => {
          this.getCarrierList(this.vehicleCapacity.page);
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
          done();
        })
        .catch(() => {});
    },
    vehicleCapacityRowDel(row, index) {
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          return carrierRemove([row.id]);
        })
        .then(() => {
          this.getCarrierList(this.vehicleCapacity.page);
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
        });
    },
    vehicleInUseInfoSelectionChange(list) {
      this.inUseSelectionList = list;
    },
    queryInUseInfo(row) {
      this.vehicleInUseInfoOption.selection = false;
      this.vehicleInUseInfoOption.menu = true;
      this.isBatchUnbinding = false;
      this.inUseInfoShowDialog = true;
      this.findInUseInfo([row.sequenceNumber]);
    },
    unbinding(row = {}) {
      let selectSequenceNumberList = [];
      let msg = '';
      if (this.isBatchUnbinding) {
        if (this.inUseSelectionList.length === 0) {
          this.$message.warning('请选择至少一条数据');
          return;
        }
        this._forEach(this.inUseSelectionList, (item) => {
          selectSequenceNumberList.push(item.sequenceNumber);
          if (!msg) {
            msg = msg + `载具${item.sequenceNumber}与产品${item.partNo}`;
          } else {
            msg = msg + `、载具${item.sequenceNumber}与产品${item.partNo}`;
          }
        });
      } else {
        selectSequenceNumberList.push(row.sequenceNumber);
        msg = `载具${row.sequenceNumber}与产品${row.partNo}`;
      }
      this.$confirm(`该操作将解除${msg}的绑定关系，请谨慎操作！`, {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        unbindingCarrier(selectSequenceNumberList).then((res) => {
          this.$message.success(res.data.msg);
          let sequenceList = [];
          if (this.isBatchUnbinding) {
            this._forEach(this.vehicleInUseInfoList, (item) => {
              sequenceList.push(item.sequenceNumber);
            });
          } else {
            sequenceList.push(row.sequenceNumber);
          }
          this.findInUseInfo(sequenceList);
        });
      });
    },
    batchUnbinding() {
      if (this.selectionList.length === 0) {
        this.$message.warning('请选择至少一条数据');
        return;
      }
      this.vehicleInUseInfoOption.selection = true;
      this.vehicleInUseInfoOption.menu = false;
      this.isBatchUnbinding = true;
      this.inUseInfoShowDialog = true;
      let list = [];
      this._forEach(this.selectionList, (item) => {
        list.push(item.sequenceNumber);
      });
      this.findInUseInfo(list);
    },
    findInUseInfo(list) {
      getInuseInfo(list).then(
        (res) => {
          this.vehicleInUseInfoList = this._get(res, 'data.data', []);
        },
        (error) => {
          this.vehicleInUseInfoList = [];
        }
      );
    },
    vehicleOpen() {
      this.vehicleCapacityList = [];
      this.$set(this.vehicleCapacity.search, 'partNo', '');
      this.getCarrierList(this.vehicleCapacity.page);
    },
    getCarrierList(page) {
      this.vehicleCapacity.loading = true;
      carrierPageList(page.currentPage, page.pageSize, Object.assign({ carrierId: this.rowData.id }, this.vehicleCapacity.search))
        .then((res) => {
          let data = res.data.data;
          this.vehicleCapacity.page.total = data.total;
          this.vehicleCapacityList = data.records;
          this.vehicleCapacity.loading = false;
        })
        .catch(() => {});
    },
    searchVehicleChange(params, done) {
      this.vehicleCapacity.search = params;
      this.vehicleCapacity.page.currentPage = 1;
      this.getCarrierList(this.vehicleCapacity.page);
      done();
    },
    searchVehicleReset() {
      this.vehicleCapacity.search = {};
      this.getCarrierList(this.vehicleCapacity.page);
    }
  }
};
</script>
<style lang="scss" scoped>
.vehicleAccountDialog {
  ::v-deep .avue-crud__menu {
    display: none;
  }
}
.subTitle {
  font-size: 16px;
  font-weight: bold;
  color: rgba(0, 0, 0, 0.85);
  .mr10 {
    margin-right: 10px;
  }
}
</style>
